//  开发环境意味着什么 ?
// 1. 服务器
// 2. 性能
// 3. 实时可查看
var path = require("path");
var HtmlPlugin = require("html-webpack-plugin");
var OpenBrower = require("open-browser-webpack-plugin");

console.log(path.resolve(__dirname,"./dev"));
module.exports = {
      mode : "development",
      entry : {
            "scripts/main" : "./src/main.js",
            // "scripts/hello" : "./src/hello/index.js",
            // "scripts/world" : "./src/world/index.js",
            // "images" : "./src/static/images/timg.jpg",
            // "jquery" : "jquery"
      },
      output : {
            path : path.resolve(__dirname,"./dev"),
            filename : "[name]-[hash:4].js"
      },
      module : {
            rules : [
                  {
                        test : /\.(css|scss)/,
                        // 以哪个loader进行输出;
                        use : [
                              { loader: "style-loader" },
                              { loader: "css-loader" },
                              { loader: "sass-loader" },

                        ]
                  },
                  {
                        test : /\.(jpg|png|gif)$/,
                        use : {
                              loader : "file-loader",
                              options : {
                                    name : "[name]-[hash].[ext]",
                                    publicPath: "images/",
                                    outputPath: 'images/'
                              }
                        }
                  },
                  {
                        test: /\.tsx?$/,
                        use: 'ts-loader',
                        exclude: /node_modules/
                  },
                  {
                        test : /\.(js|jsx)$/,
                        use : {
                              loader : "babel-loader",
                              options : {
                                    presets : [
                                          "env",
                                    ]
                              }
                        }
                  }
            ]
      },
      devServer : {
            contentBase : path.resolve(__dirname,"dev"),
            host : "localhost",
            // 服务器压缩是否开启
            compress : true ,
            // 配置服务器端口号
            port : 8888,
      },
      plugins : [
            new HtmlPlugin({
                  filename : "index.html",
                  template : "./src/index.html",
                  chunks: ['scripts/main'],
                  inject: true

            }),
            // new HtmlPlugin({
            //       filename : "hello.html",
            //       template : "./src/hello/hello.html",
            //       chunks :["scripts/hello"],
            //       inject: true
            // }),
            // new HtmlPlugin({
            //       filename : "world.html",
            //       template : "./src/world/world.html",
            //       chunks : ["scripts/world"],
            //       inject: true
            // }),

            new OpenBrower({ url: 'http://localhost:8888' })
      ]
}
